//
//  ZpBarButtonItem.m
//  WeiBo_OC
//
//  Created by MacBook Pro on 16/5/25.
//  Copyright © 2016年 MacBook Pro. All rights reserved.
//

#import "ZpBarButtonItem.h"

@interface ZpBarButtonItem ()
@property (nonatomic, weak) UIButton *btn;
@end

@implementation ZpBarButtonItem

+ (instancetype) barButtonItemWithImageName:(NSString *)imageName andTitle:(NSString *)title andTarget:(UIViewController *) target andSelecor:(SEL)selector andTitleNormalColor:(UIColor *)normalColor andTitleHightColor:(UIColor *)hightColor
{
    UIButton *btn = [[UIButton alloc] init];
    
    if (imageName) {
        NSString *hightImageName = [NSString stringWithFormat:@"%@_highlighted",imageName];
        [btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:hightImageName] forState:UIControlStateHighlighted];
    }
    
    if (title) {
        [btn setTitle:title forState:UIControlStateNormal];
        [btn setTitleColor:normalColor forState:UIControlStateNormal];
        [btn setTitleColor:hightColor forState:UIControlStateHighlighted];
    }
    
    [btn sizeToFit];
    ZpBarButtonItem *item = [[ZpBarButtonItem alloc] initWithCustomView:btn];
    

    [btn addTarget:target action:selector forControlEvents:UIControlEventTouchDown];
    
    return item;
}

- (instancetype)initWithCustomView:(UIView *)customView{
    if (self = [super initWithCustomView:customView]) {
        self.btn = (UIButton *)customView;
    }
    return self;
}


@end
